package com.cg.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/register")
public class RegisterSelvet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String age = req.getParameter("age");
        String phone = req.getParameter("phone");
        //获取复选框爱好的值
        String[] hobbies = req.getParameterValues("hobbies");

        resp.setContentType("text/html;charset=utf-8");

        PrintWriter writer = resp.getWriter();
        writer.println("用户名："+username+"</br>");
        writer.println("年龄:"+age+"</br>");
        writer.println("手机号："+phone+"</br>");

        //遍历输入爱好
        if (hobbies!=null){
            for (String hobby : hobbies){
                writer.println("爱好:"+hobby+"</br>");
            }
        } else {
            writer.println("爱好：其他");
        }
    }
}
